const express = require('express');
const router = express.Router();
const db = require("../../../../util/dbConfig/dbConfig")

router.post('/',async (req,res)=>{
    if(req.session.userInfo.admin !== 1){
        return res.send({
            code: 3,
            msg: '非管理员不可访问'
        })
    }
    let {
        soldId,  //出售订单编号
        sheepId,    //该羊编号
        die,        //是否死亡
        dieDate     //死亡日期
    } = req.body
    if(!sheepId || !die || !dieDate){
        return res.send({
            code: 1,
            msg: '参数错误'
        })
    }
    soldId= soldId? soldId:null
    try{
        //标记死亡
        let sqlIsDie = `update sheep set SOLD_ID=?,DIE=?,DIE_DATE=? where ID=?`
        let sqlIsDieArr = [soldId,die,dieDate,sheepId]
        let result = await db.SySqlConnect(sqlIsDie,sqlIsDieArr)
        if(result.changedRows !==0){
            //后续删除生产性能信息

            return res.send({
                code: 0,
                msg: '修改成功'
            })
        }else {
            return res.send({
                code: 2,
                msg: '修改失败'
            })
        }
    }catch (e) {
        console.log(e);
        return res.send({
            code: 4,
            msg: '服务器错误,请稍后再试'
        })
    }
})


module.exports = router
